const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const CleanWebpackPlugin = require('clean-webpack-plugin');//清除打包的文件
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

const ENV = process.env.NODE_ENV || 'production';
const options = {
	publicPath: 'dist',
	loaders: {
		styles: ExtractTextPlugin.extract({
      		fallback: 'style-loader',
      		use: [
        		'css-loader',
        		'postcss-loader'
      		]
      	}),
      	imageAssets:'url-loader?limit=6000&name=[path][name]-[hash:8].[ext]',
      	iconFonts: [{
      		loader: 'url-loader',
      		query: {
      			limit: 10000,
      			name: '[path][name]-[hash:8].[ext]'
      		}
      	}]
	},
	globals: {
        'process.env': {
            'NODE_ENV': JSON.stringify(ENV)
        }
    }
}


module.exports = function (args) {
    options.dirname = args.dirname;
    options.env = ENV;
    options.isDev = args.isDev;
    return webpackMerge(require('./webpack.base')(options), {
        plugins: [
			new ExtractTextPlugin({
	        	filename: 'css/[name].[hash:8].css'
	      	}),
	      	new CleanWebpackPlugin(['dist']),
	      	new UglifyJsPlugin()
		]
    });
};